#pragma once

#include "gst/gstelement.h"
#include "nvds_custom_meta.h"
#include <gst/gst.h>
#include <nvbufsurface.h>

class NVDSSourcebin
{
public:
    /**
     * @brief Construct a new NVDSSourcebin object
     *
     * @param bin_name
     * @param uri
     * @param use_transform
     * @param img_quality
     * @param scale
     * @param width
     * @param height
     */
    explicit NVDSSourcebin(const char *bin_name,
                           const char *uri,
                           bool        use_transform = false,
                           int         img_quality   = 30,
                           bool        scale         = false,
                           int         width         = 1920,
                           int         height        = 1080);
    ~NVDSSourcebin();

private:
    GstElement *createSourcebin(const char *bin_name, const char *uri);
    static void padAddedCallback(GstElement *decodebin, GstPad *decoder_src_pad, gpointer data);
    static void childAddedCallback(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data);
    static void surfaceTransform(
        NVDSCustomMeta *user_metadata, NvBufSurface *surface, int index, int quality, bool scale, int scale_width, int scale_height);
    static GstPadProbeReturn probeCallback(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);

public:
    void bindStreammux(const char *pad_name, GstElement *streammux);
    void bindPipeline(GstElement *pipeline);

    GstElement *getSourcebin()
    {
        return m_sourcebin;
    }

private:
    GstElement *m_sourcebin;
    bool        m_surfaceTransform;  // 是否开启 surfaceTransform
    int         m_jpgencQuality;     // 图片质量 1-100
    bool        m_jpgencScaleEnable; // 是否开启图片缩放
    int         m_jpgencScaleWidth;  // 图片缩放宽度
    int         m_jpgencScaleHeight; // 图片缩放高度
};
